import axios from "axios";
export default function request(url, method = "GET", ...args) {
  // console.log(args); 
 // args 参数是数组 下面的args[0]是索引为0的数据从数组中传过来
  return new Promise((resolve) => {
    if (method === "GET") {
      axios
        .get(url, args[0])
        .then((data) => {
          resolve(data);
        })
        .catch(() => {
          return new Error("get请求异常");
        });
    } else if (method === "POST") {
      axios
        .post(url, args[0])
        .then((data) => {
          resolve(data);
        })
        .catch(() => {
          return new Error("POST请求异常");
        });
    }
  });
}
